package br.com.slsystems.travianbot.view;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import java.util.Observable;

public class LoginDialog extends Observable{

	private Shell dialog = null;
	
	public LoginDialog(Shell shell) {
		
		dialog = new Shell(shell, SWT.CLOSE | SWT.APPLICATION_MODAL);		
		dialog.setText("Login");
		//dialog.setSize(200, 200);   
		GridLayout gridLayout = new GridLayout(4, false);
	    gridLayout.verticalSpacing = 8;

	    dialog.setLayout(gridLayout);
	    
	    dialog.addDisposeListener(new DisposeListener() {
	    	@Override
	    	public void widgetDisposed(DisposeEvent e) {
	    		setChanged();
                notifyObservers("Fechando janela LoginDialog");
	    	}
	    });

	    // Title
	    Label label = new Label(dialog, SWT.NULL);
	    label.setText("Title: ");

	    Text title = new Text(dialog, SWT.SINGLE | SWT.BORDER);
	    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	    gridData.horizontalSpan = 3;
	    title.setLayoutData(gridData);

	    // Author(s)
	    label = new Label(dialog, SWT.NULL);
	    label.setText("Author(s): ");

	    Text authors = new Text(dialog, SWT.SINGLE | SWT.BORDER);
	    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	    gridData.horizontalSpan = 3;
	    authors.setLayoutData(gridData);

	    // Cover
	    label = new Label(dialog, SWT.NULL);
	    label.setText("Cover: ");

	    gridData = new GridData();
	    gridData.verticalSpan = 3;
	    label.setLayoutData(gridData);

	    CLabel cover = new CLabel(dialog, SWT.NULL);

	    gridData = new GridData(GridData.FILL_HORIZONTAL);
	    gridData.horizontalSpan = 1;
	    gridData.verticalSpan = 3;
	    gridData.heightHint = 100;
	    gridData.widthHint = 100;

	    cover.setLayoutData(gridData);

	    // Details.
	    label = new Label(dialog, SWT.NULL);
	    label.setText("Pages");

	    Text pages = new Text(dialog, SWT.SINGLE | SWT.BORDER);
	    pages.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

	    label = new Label(dialog, SWT.NULL);
	    label.setText("Publisher");

	    Text pubisher = new Text(dialog, SWT.SINGLE | SWT.BORDER);
	    pubisher.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

	    label = new Label(dialog, SWT.NULL);
	    label.setText("Rating");

	    Combo rating = new Combo(dialog, SWT.READ_ONLY);
	    rating.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
	    rating.add("5");
	    rating.add("4");
	    rating.add("3");
	    rating.add("2");
	    rating.add("1");

	    // Abstract.

	    label = new Label(dialog, SWT.NULL);
	    label.setText("Abstract:");

	    Text bookAbstract =
	      new Text(
	        dialog,
	        SWT.WRAP
	          | SWT.MULTI
	          | SWT.BORDER
	          | SWT.H_SCROLL
	          | SWT.V_SCROLL);
	    gridData =
	      new GridData(
	        GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
	    gridData.horizontalSpan = 3;
	    gridData.grabExcessVerticalSpace = true;

	    bookAbstract.setLayoutData(gridData);

	    // Button.
	    Button enter = new Button(dialog, SWT.PUSH);
	    enter.setText("Enter");

	    enter.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                 setChanged();
                 notifyObservers("Retorno do notify observers");
            }
      });
	    
	    gridData = new GridData();
	    gridData.horizontalSpan = 4;
	    gridData.horizontalAlignment = GridData.END;
	    enter.setLayoutData(gridData);
	    
	   

	    // Fill information.

	    title.setText("Professional Java Interfaces with SWT/JFace");
	    authors.setText("Jack Li Guojie");
	    pages.setText("500pp");
	    pubisher.setText("John Wiley & Sons");
	    //cover.setBackground(new Image(dialog.getDisplay(), "java2s.gif"));
	    bookAbstract.setText(
	      "This book provides a comprehensive guide for \n"
	        + "you to create Java user interfaces with SWT/JFace. ");

	    dialog.pack();
	    dialog.open();
		
	}	
	
}